#!/bin/bash
#
#  forkexecd        Startup script for process management service
#
# chkconfig: 2345 13 88
# description: Manages subprocesses independently from a multithreaded program.
### BEGIN INIT INFO
# Provides: forkexecd
# Required-Start: $local_fs $network $syslog message-switch
# Required-Stop: $local_fs $syslog
# Should-Start: $syslog message-switch
# Should-Stop: $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Manage subprocesses
# Description:       Manage subprocesses independently from a multithreaded program.
### END INIT INFO

# Source function library.
. /lib/lsb/init-functions

RETVAL=0
PIDFILE=/var/run/forkexecd.pid

prog=forkexecd
exec=/usr/sbin/forkexecd
if [ -d /var/lock/subsys ] ; then
    lockfile=/var/lock/subsys/$prog
else
    lockfile=/var/lock/$prog
fi

# Source config
if [ -f /etc/sysconfig/$prog ] ; then
    . /etc/sysconfig/$prog
fi

start() {
	[ -x $exec ] || exit 5

	umask 077

        echo -n $"Starting forkexecd: "
        start_daemon -p "$PIDFILE" $exec -pidfile "$PIDFILE" -daemon $FORKEXEC_OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch $lockfile
        return $RETVAL
}
stop() {
        echo -n $"Shutting down forkexecd: "
        killproc -p "$PIDFILE" $exec
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f $lockfile
        return $RETVAL
}
rhstatus() {
        status_of_proc -p "$PIDFILE" $exec $prog
}
restart() {
        stop
        start
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        restart
        ;;
  reload)
        exit 3
        ;;
  force-reload)
        restart
        ;;
  status)
        rhstatus
        ;;
  condrestart|try-restart)
        rhstatus >/dev/null 2>&1 || exit 0
        restart
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|condrestart|try-restart|reload|force-reload|status}"
        exit 3
esac

exit $?
